//
//  FamilyManageOneCell.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/29.
//  Copyright © 2020 tym. All rights reserved.
//

#import "FamilyManageOneCell.h"
#import "Masonry.h"
#import "UserTool.h"
#import "UIImageView+WebCache.h"
#import "UIImageView+YPImage.h"
#import "UserModel.h"
#import "FamilyModel.h"
#import "Colors.h"
#import "Sizes.h"
#import "UIView+ZFFrame.h"
#import "Fonts.h"
#import "TYMLabel.h"
#import "TYMButton.h"
@interface FamilyManageOneCell()

@property(nonatomic,weak) TYMLabel *sectionLab;
@property(nonatomic,weak) UIView *lineView;

@property(nonatomic,weak) UIView *conView;
@property(nonatomic,weak) UIImageView *headImage;
@property(nonatomic,weak) TYMLabel *mobilLab;
@property(nonatomic,weak) TYMLabel *optionLab;
@property(nonatomic,weak) TYMButton *optionBtn;
@end

@implementation FamilyManageOneCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initUI];
    }
    return self;
}

-(void)initUI{
    
    self.backgroundColor = [UIColor whiteColor];
    
    TYMLabel *sctLab = [TYMLabel lb_text:@"申请消息管理" font:Font_Regular(15) color:rgba(155, 155, 155)];
    sctLab.frame = CGRectMake(15, 0, 200, 44);
    [self.contentView addSubview:sctLab];
    self.sectionLab = sctLab;
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 44, ScreenWidth- 30 , 1)];
    line.backgroundColor = rgba(242, 242, 242);
    [self.contentView addSubview:line];
    self.lineView = line;
    
    UIView *conView = [[UIView alloc] initWithFrame:CGRectMake(0, 54, ScreenWidth - 30, 70)];
    [self.contentView addSubview:conView];
    self.conView = conView;
    
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_home3"]];
    image.layer.masksToBounds = YES;
    image.layer.cornerRadius = 25;
    image.frame = CGRectMake(15, 10, 50, 50);
image.contentMode = UIViewContentModeScaleAspectFill;
    [self.conView addSubview:image];
    self.headImage = image;
    
    TYMLabel *moLab = [TYMLabel lb_text:@"" font:Font_Medium(15) color:rgba(74, 74, 74)];
    moLab.frame = CGRectMake(self.headImage.zf_right+10, 15, 150, 21 );
    [self.conView addSubview:moLab];
    self.mobilLab = moLab;
    
    TYMLabel *opLab = [TYMLabel lb_text:@"申请加入您的家庭" font:Font_Regular(12) color:rgba(76, 132, 255)];
    opLab.frame = CGRectMake(moLab.zf_x, 38, 120, 16.5);
    [self.conView addSubview:opLab];
    self.optionLab = opLab;
    
    TYMButton *btn = [TYMButton btn_text:@"取消" color:rgba(74, 74, 74) font:Font_Regular(11)];
    btn.layer.borderWidth = 1;
    btn.frame = CGRectMake(ScreenWidth -15 - 30-55, 22.5, 55, 25);
    btn.layer.cornerRadius = 3;
    [btn addTarget:self action:@selector(optionAction:) forControlEvents:UIControlEventTouchUpInside];
    btn.layer.borderColor = rgba(74, 74, 74).CGColor;
    [self.conView addSubview:btn];
    self.optionBtn = btn;
}

-(void)optionAction:(id)sender{
    if (self.optionBlock) {
        self.optionBlock(self.model.applyid);
    }
}

-(void)setModel:(ApplyforModel *)model{
    _model = model;
    
    
    //家长操作
    if(![[UserTool getLogInUser].mobile isEqualToString:model.mobile]){
        self.mobilLab.text = model.mobile;
        [self.optionBtn setTitle:@"操作" forState:UIControlStateNormal];
    }else{ //成员操作
        self.mobilLab.textColor = rgba(253, 93, 110);
        self.mobilLab.font = Font_Medium(15);
        self.mobilLab.text = @"申请中";
        [self.optionBtn setTitle:@"取消" forState:UIControlStateNormal];
        self.optionLab.textColor = rgba(74, 74, 74);
        self.optionLab.font = Font_Regular(12);
        self.optionLab.text = [NSString stringWithFormat:@"您申请加入%@",model.familyName?model.familyName:@""];
    }
    
    NSString *headUrl = [_model getheadImage];
    [self.headImage sd_setImageWithURL:[NSURL URLWithString:headUrl] placeholderImage:[UIImage imageNamed: @"icon_home3"]];
}

-(void)hiddenSectionView{
    self.sectionLab.hidden = YES;
    self.lineView.hidden = YES;
    
    self.conView.frame = CGRectMake(0, 0, ScreenWidth - 30, 70);
}

-(void)showSectionView{
    self.sectionLab.hidden = NO;
    self.lineView.hidden = NO;
    
    self.conView.frame = CGRectMake(0,54, ScreenWidth - 30, 70);
}

+(NSString*)identifier{
    return @"FamilyManageOneCell";
}

+(CGFloat)cellForHeight{
    return 70;
}

@end
